package com.tecsoluction.transportecerto;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.Toast;

public class Configuracao extends MapActivity implements LocationListener,OnClickListener{
	
	private MapView mapa ;
	private MapController controladorMapa;
	private double longitude;
	private double latitude;
//	private Button bt_tracaRota = null;
	private MyLocationOverlay minhaLocalizacao; 
	private Location localizacao=null;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.configuracao_layout);

		mapa = (MapView) findViewById(R.id.mapViewlayout);
		controladorMapa = mapa.getController();

		//    	Latitudes da Faculdade Mauricio de Nassau   
		latitude = -8.217978;
		longitude = -34.931033;
  
		minhaLocalizacao = new MyLocationOverlay(this, mapa);
        mapa.getOverlays().add(minhaLocalizacao);
        localizacao = retornaLocationManager().getLastKnownLocation(LocationManager.GPS_PROVIDER);
		
        if (localizacao != null)
		{
			Log.i("onLocationChanged","Lat: "+localizacao.getLatitude()+"Lon:"+localizacao.getLongitude());
		Toast.makeText(getBaseContext(), "Lat: "+localizacao.getLatitude()+"Lon:"+localizacao.getLongitude(), Toast.LENGTH_LONG).show();
			GeoPoint gp = posicao(localizacao.getLatitude(),localizacao.getLongitude());
			controladorMapa.setCenter(gp);
		}
    		

        retornaLocationManager().requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
   	 
		controladorMapa.animateTo(posicao(latitude,longitude));
		LocalOverlay localinicial= new LocalOverlay(posicao(latitude,longitude),R.drawable.icone_apontador);
		mapa.getOverlays().add(localinicial);
		mapa.setSatellite(false);
		mapa.displayZoomControls(true); 
		mapa.setClickable(true);
		mapa.setBuiltInZoomControls(true);
		LinearLayout linearZoonMapa = (LinearLayout) findViewById(R.id.zoonMapalayout);
		linearZoonMapa.addView(mapa.getZoomControls());
		controladorMapa.setZoom(18);
		mapa.invalidate();

	


}

	private LocationManager retornaLocationManager() {
		LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		return locationManager;
	}

	public GeoPoint posicao(double latitude ,double longetude)
	{
		GeoPoint geopoint = new GeoPoint((int)(latitude *1E6), (int)(longetude* 1E6));
	
	
		return geopoint;
	}

	public void onLocationChanged(Location arg0) {
		// TODO Auto-generated method stub
		
	}

	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}


}
